<?php
class Flashimg extends CWidget
{
	protected $assetUrl;
	public $id = 'flashImg';
	public $width = 698;
	public $height = 250;
	public $images = array();
	public $preview = array(
		'01.gif',
//		'02.gif',
		'03.gif',
		'04.gif',
		'05.gif',
	);



	public function init(){
		$this->images = array(
			array('pic'=>'01.jpg','url'=>$this->controller->createUrl('/item/list/',array('keyword'=>'麦包包')),'alt'=>'买包包？麦包包！'),
//			array('pic'=>'02.gif','url'=>$this->controller->createUrl('/reliable/toplist',array('type'=>'fuzhuang')),'alt'=>'让网上购物变得更加简单！'),
			array('pic'=>'03.jpg','url'=>$this->controller->createUrl('/reliable/toplist',array('type'=>'qudou')),'alt'=>'无痘青春，靓丽好心情！'),
			array('pic'=>'04.gif','url'=>$this->controller->createUrl('/reliable/toplist',array('type'=>'jianfei')),'alt'=>'想SHOW？你就瘦出来！'),
			array('pic'=>'05.jpg','url'=>$this->controller->createUrl('/item/list/',array('keyword'=>'奶粉')),'alt'=>'优质奶粉，把好宝宝成长第一关！'),
		);
		$this->assetUrl = Yii::app()->assetManager->publish(dirname(__FILE__).'/asset');
		$this->regFiles();
		parent::init();
	}

	public function run(){
		/*
		$images = CFileHelper::findFiles(Yii::app()->assetManager->getPublishedPath(dirname(__FILE__).'/asset').DS.'images',array(
			'fileTypes'=>array('jpeg','jpg','png','gif'),
			'level'=>0,
		));
		$preview = CFileHelper::findFiles(Yii::app()->assetManager->getPublishedPath(dirname(__FILE__).'/asset').DS.'images'.DS.'thumb',array(
			'fileTypes'=>array('jpeg','jpg','png','gif'),
			'level'=>0,
		));
		*/

		echo'<div id="'.$this->id.'">';
		foreach($this->images as $key => $val){
			$class = "flashImg_item";
			if ($key ==0) $class .= " flashImg_current";
			echo '
			<div class="'.$class.'"><a href="'.$val['url'].'" target="_blank"><img src="'.$this->assetUrl.'/images/'.$val['pic'].'" alt="'.$val['alt'].'" /></a></div>';
		}
		echo '
		<div class="flashImg_bottom">
			<div class="preview_images">';
		foreach($this->preview as $k => $v){
			$class = '';
			if($k == 0) $class = ' class="current_prev"';
			echo '
				<a'.$class.' href="javascript:void(0);" onfocus="this.blur()"><img src="'.$this->assetUrl.'/images/thumb/'.$v.'" alt="缩略图"  /></a>';
		}
		echo "
			</div>
		</div>
		</div>";
	}

	protected function regFiles(){
		$cs = Yii::app()->clientScript;
		$cs->registerCoreScript('jquery');
		$cs->registerScriptFile($this->assetUrl.'/script/custom.js');
		$cs->registerCssFile($this->assetUrl.'/css/style.css');
		$cs->registerCss(__CLASS__,"
			#".$this->id."{height:".$this->height."px;position:relative;}
			#".$this->id." .flashImg_current{display:block;}
			.flashImg_item,.flashImg_item img{width:".$this->width."px;height:".$this->height."px;}
		");
	}
}